<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="author" content="wangyuguo">
		<title>个人帐户维护</title>
		<script language="javascript" src="../script/common.js" type="text/javascript"></script>
		<script language="javascript" src="../script/card.js" type="text/javascript"></script>
		
		<!--动态js-->
<script type="text/javascript">
	//页面加载方法
	var pageData = {cardPin : null}
	function load(){
		Eui.showNavigation();	
		Rpc.loadPage("cardInfoDiv","card_info_div.html");										// 显示导航栏
		CardMgnt.customer.show("customerdiv",null,CardMgnt.PERSONALALL)
		CardMgnt.cardUser.show("bindinfodiv",null,CardMgnt.PERSONALALL)
	}		
		
	//读卡
	function onReadCard(){
		try{
			var data = CardMgnt.onFindCard("readCardForm","mgntQueryService.getCardUserInfo",null,true);
			if (!CardMgnt.checkInUseCard(data.card)) return;
			if (data.cardUser.type != CardUserType.NAME || data.cardType.anonymous) {showError("该卡不是个人记名卡！");onCancel();return;}
			pageData.cardPin = data.cardPin;
			
			CardMgnt.cardUser.showData("bindinfodiv",data,CardMgnt.PERSONALALL);
			CardMgnt.customer.showCustomer("customerdiv",data.customer,CardMgnt.PERSONALALL);
			$("syncBtn").disabled = false;
		}catch(e){
			showError(e.description);
		}
	}
	//保存帐户信息，并同步卡数据
	function saveAndSyncData(){
		var asn = readCardForm.asn.value;
		if (!checkForm(CardMgnt.customer.formName)) return;
		if (!checkForm(CardMgnt.cardUser.formName)) return;
		if (!CardMgnt.checkCardAsn(asn)){onCancel();return;}
		var customer = CardMgnt.customer.get();
		var cardUser = CardMgnt.cardUser.get();
		
		if (!showQuestion("是否修改客户帐户信息？")) return;
		
		var usePin = cardUser.usePin == "true";
		cardUser.usePin = getNeedPin();
		DWR.call("customerService.savePersonalCustomerAndUser",customer,cardUser,function(data){
			showInformation("客户帐户信息保存成功！");
			
			while(true){
				try{
					CardMgnt.syncCardData(asn,pageData.cardPin);
					break;
				}catch(e){
					if (showQuestion("同步卡数据失败！是否重试？<br>错误原因："+e.description)){
						continue;
					}else
						return;
				}
			}
			try{
				if (cardUser.usePin != usePin)
					CardMgnt.usePinApp(asn,usePin,pageData.cardPin);
			}catch(e){
				showError(e.description);return;
			}
			onCancel();
		});
	}
	
	//重置
	function onCancel(){
		pageData = {}
		CardMgnt.resetForm(CardMgnt.customer.formName)
		CardMgnt.cardUser.show("bindinfodiv",null,CardMgnt.PERSONALALL)
		readCardForm.reset();
		$("syncBtn").disabled = true;
	}
</script>
	</head>
	
<body onload="load()">
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<div id="cardInfoDiv" class="form">	
		
	</div>
	<div id='tabsdiv' align="left">
	</div>
	<div id="customerdiv" class="form">
	</div>
	<div id="bindinfodiv" class="form">
	</div>
	<p>
		<button id="returnbtn" onclick="onReadCard()">读 卡</button>
		<button id="syncBtn" onclick="saveAndSyncData()" disabled>保存并写卡</button>
		<button onclick="onCancel()">重 置</button>
	</p>
</body>
</html>
